package cn.mldn.microcloud.service.impl;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.mldn.microcloud.service.IMessageService;

@Service
public class MessageServiceImpl implements IMessageService {

    @Autowired
    private AmqpTemplate amqpTemplate;

    /*
     * 根据消息队列发送消息
     */
	@Override
	public boolean sendMessage(String queue, String message) {
		try{
			amqpTemplate.convertAndSend(queue, message);
			return true;
		}catch(AmqpException e){
			e.printStackTrace();
			return false;
		}	
	}

	/*
	 * 根据exchange发送消息
	 * @see cn.mldn.microcloud.service.IMessageService#sendMessage(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public boolean sendMessage(String exchange, String key, String message) {
		try{
			amqpTemplate.convertAndSend(exchange,key, message);
			return true;
		}catch(AmqpException e){
			e.printStackTrace();
			return false;
		}
	}

}
